<?php

namespace api\modules\v1\controllers\member;

use api\controllers\UserAuthController;
use common\enums\AccountTypeEnum;
use common\helpers\ResultHelper;
use common\models\forms\BankAccountForm;
use common\models\member\BankAccount;
use Yii;

/**
 * 提现账号
 *
 * Class BankAccountController
 * @package api\modules\v1\controllers\member
 * @author  
 */
class BankAccountController extends UserAuthController
{
    /**
     * @var BankAccountForm
     */
    public $modelClass = BankAccountForm::class;

    
    public function actionList($limit = 10, $offset = 0)
    {
        $user = Yii::$app->user->identity->member;
        $list = BankAccount::find()
            ->where(['member_id' => $user->id])
            ->orderBy('id desc')
            ->asArray()
            ->limit($limit)->offset($offset * $limit)->asArray()
            ->all();
        return ResultHelper::json(200, 'ok', [
            'list' => $list
        ]);
    }

    public function actionAccountType()
    {
        return AccountTypeEnum::getMap();
    }

    public function actionCreate()
    {
        $model = new $this->modelClass;
        if(Yii::$app->request->post()){
            $member = Yii::$app->user->identity->member;

            $model->attributes = Yii::$app->request->post();
            $model->member_id = $member->id;
            if($model->save()){
                return true;
            }else{
                return ResultHelper::json('422',$this->getError($model));
            }
        }
    }

}